package in.muton.edushare.panels.upload.thin;

import in.muton.edushare.pages.common.EdusharePanel;

import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.PageCreator;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;

public abstract class ModalMultiUploadButtonPanel extends EdusharePanel {

	private static final long serialVersionUID = -6359793736176636724L;

	public ModalMultiUploadButtonPanel(String id, IModel<String> tempUploadIdModel) {
		super(id, tempUploadIdModel);
		loadPanel();
	}

	private void loadPanel() {
		
		/** Modal Window */
		final ModalWindow uploadWindow = new ModalWindow("uploadWindow");
		uploadWindow.setPageCreator(new PageCreator(){

			public Page createPage() {
				return new MultiUploadModalPage((IModel<String>)getDefaultModel(), uploadWindow);
			}
			
		});
		uploadWindow.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
			
			public boolean onCloseButtonClicked(AjaxRequestTarget target) {
				onUploadWindowClose(target);
				return true;
			}
			
		});
		uploadWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
			
			public void onClose(AjaxRequestTarget target) {
				onUploadWindowClose(target);
			}
		});
		uploadWindow.setWidthUnit("px");
		uploadWindow.setInitialWidth(400);
		uploadWindow.setHeightUnit("px");
		uploadWindow.setInitialHeight(240);
		add(uploadWindow);
		
		/** Show Modal Window Button */
		AjaxButton showUploadWindowButton = new AjaxButton("showUploadWindow"){

			private static final long serialVersionUID = -4022196328128251202L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				uploadWindow.show(target);
			}
			
		};
		
		showUploadWindowButton.setDefaultFormProcessing(false);
		add(showUploadWindowButton);
		
	}
	
	protected abstract void onUploadWindowClose(AjaxRequestTarget target);
}
